package com.enfo.zjabank.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.enfo.zjabank.dao.GridDao;
import com.enfo.zjabank.model.Pager;
import com.enfo.zjabank.service.ChartsService;
import com.enfo.zjabank.service.GridService;
import com.enfo.zjabank.tool.GridUtils;
import com.enfo.zjabank.tool.PagerPropertyUtils;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by zhoum on 2016/8/3.
 */
@Controller
@RequestMapping("/charts")
public class ChartsController {
    @Autowired
    private ChartsService chartsService;
    @Autowired
    private GridService gridService;
    //饼图的数据
    @RequestMapping(value = "/totalReportData", method = RequestMethod.GET)
    public @ResponseBody
    Map<String,BigDecimal[]> totalReportData(){
        return chartsService.totalReportData();
    }
    @RequestMapping(value = "/page/{chartsName}",method = RequestMethod.GET)
    public String getPage(@PathVariable String chartsName,Model model){
        model.addAttribute("chartsName",chartsName);
        return "charts/iframe";
    }
    @RequestMapping(value = "/{chartsName}",method = RequestMethod.GET)
    public String show(@PathVariable String chartsName){
        return "charts/"+chartsName;
    }
    @RequestMapping(value = "/grid",method = RequestMethod.POST)
    public @ResponseBody String getGrid(String gridPager){
        //		获取SQL
//        StringBuffer sql = new StringBuffer();
//        sql.append("select * from user u where 1=1 ");
//		定义参数列表
//        List<Object> args = new ArrayList<Object>();
//		判断是否包含自定义参数
//        Map<String, Object> parameters = pager.getParameters();
//        if(parameters.containsKey("like_user_code_or_user_name")){
//            String like_user_code_or_user_name = MapUtils.getString(parameters, "like_user_code_or_user_name");
//            if(like_user_code_or_user_name!=null&&!"".equals(like_user_code_or_user_name.trim())){
//                sql.append("and u.user_code like ? or u.user_name like ? ");
//                args.add("%"+like_user_code_or_user_name+"%");
//                args.add("%"+like_user_code_or_user_name+"%");
//            }
//        }
//		执行查询
//        GridUtils.queryForGrid(sql.toString(), pager, request, response, args.toArray());
        return gridService.listByPage(gridPager);
    }
    //折线图的列表查询
    @RequestMapping(value = "/shuju",method = RequestMethod.POST)
    public @ResponseBody String getshuju(String gridPager){
        return  gridService.listShuJu(gridPager);
    }
    //折线图的数据
    @RequestMapping(value = "/ljbbshuju", method = RequestMethod.GET)
    public @ResponseBody
    Map<String,BigDecimal[]> getLjbbshuju(){
        return gridService.listLjbbShuJu();
    }
    //柱状图的数据
    @RequestMapping(value = "/zhuzhuangshuju", method = RequestMethod.GET)
    public @ResponseBody Map<String,BigDecimal[]> getZhuZhuangshuju(){
        return gridService.listZhuZhuangShuJu();
    }
  //地区下拉框的内容
    @RequestMapping(value = "/areashuju", method = RequestMethod.GET)
    public @ResponseBody Map<String,String> getareashuju(){
        return gridService.listareaShuJu();
    }
    
  //所有任务统计与分析的数据
    @RequestMapping(value = "/tjfxshuju", method = RequestMethod.GET)
    public @ResponseBody BigDecimal[] getTjfxshuju(){
        return gridService.listTjfxShuJu();
    }
    //饼图的列表查询
    @RequestMapping(value = "/lgshuju",method = RequestMethod.POST)
    public @ResponseBody String getLgshuju(String gridPager){
        return  chartsService.listLgShuJu(gridPager);
    }
  //柱状图的列表查询
    @RequestMapping(value = "/zhuzhuanglb",method = RequestMethod.POST)
    public @ResponseBody String getZhuzhuangLb(String gridPager){
        return  gridService.listZhuzhuangLb(gridPager);
    }
    
  //柱状图的列表查询
    @RequestMapping(value = "/tjfxlb",method = RequestMethod.POST)
    public @ResponseBody String getTjfxLb(String gridPager){
        return  gridService.listTjfxLb(gridPager);
    }
    
  //概要统计的列表查询
    @RequestMapping(value = "/gytjlb",method = RequestMethod.POST)
    public @ResponseBody String getGytjLb(String params,String gridPager){
        return  gridService.listGytjLb(params,gridPager);
    }
}



